let socket;
Page({
  data: {
    stock:{
      qiongqiong:100,
      tencent:90,
      JD:60
    },
    falg:{
      qiongqiong: '',
      tencent: '',
      JD:'',
    }
  },
  connect(){
    let _this = this;
    socket =  wx.connectSocket({
      url: 'ws://localhost:8080',
    })
    socket.onMessage((data) => {
      //console.log(data);
      let data1 = JSON.parse(data.data);

      

      let oldData = _this.data.stock;
      let falg = _this.data.falg;

      for (let i in data1){
        falg[i] = _this.changeFlag(oldData[i], data1[i]);
      }

      _this.setData({
        stock: data1,
        falg: falg
      })


    })
  },
  changeFlag(oldVal,newVal){
    if (newVal < oldVal){
      return 'down'
    } else if (newVal > oldVal){
      return 'up'
    }
  },
  onLoad: function (options) {
    
  },
  onReady: function () {
    
  },
  onShow: function () {
    
  },
  onHide: function () {
    
  },
  onUnload: function () {
    
  },
  onPullDownRefresh: function () {
    
  },
  onReachBottom: function () {
    
  },
  onShareAppMessage: function () {
    
  }
})